package ConditionalOnProperty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class MyAppRunner implements CommandLineRunner {

    @Autowired(required = false) // 使得该注入为可选
    private MyService myService;

    @Override
    public void run(String... args) {
        if (myService != null) {
            myService.execute();
        } else {
            System.out.println("MyService is not active!");
        }
    }
}